package com.sr.examination.main;

import android.view.Gravity;
import android.view.View;
import android.widget.Toast;

import com.sr.examination.R;
import com.tl.commonlibrary.tool.UIUtils;
import com.tl.commonlibrary.ui.ActivityStack;

/**
 * @author JongSung
 * @Description 主界内容模块中的其他，实现了退出功能，统一运行时权限的请求，广告等
 * @date 2017/8/11 0011.
 */
public class MainOtherViewModel implements View.OnClickListener {
    public static final int READ_PHONE_STATE_PERMISSION_REQUEST_CODE = 1;
    public static final int READ_PHONE_STORAGE_PERMISSION_REQUEST_CODE = 2;
    public static final int LOCATION_PERMISSION_REQUEST_CODE = 3;
    private MainActivity parent;

    public MainOtherViewModel(MainActivity parent) {
        this.parent = parent;
    }

    public void init(boolean isReOnCreate) {
//        permissionInit();
    }

//    private void permissionInit() {
//        if (StatisticHelper.isInstalledStatistic()) {
//            //部分运行时权限请求
//            //读取手机卡
//            parent.requestPermission(Manifest.permission.READ_PHONE_STATE, READ_PHONE_STATE_PERMISSION_REQUEST_CODE);
//            //获取地理位置
//            parent.requestPermission(new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, LOCATION_PERMISSION_REQUEST_CODE);
//
//        }
//    }

    //退出时的时间
    private long mExitTime;

    public void exit() {
        if ((System.currentTimeMillis() - mExitTime) > 2000) {
            Toast toast = UIUtils.toastInstance(R.string.app_exit);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            mExitTime = System.currentTimeMillis();
        } else {
            ActivityStack.get().appExit(parent);
        }
    }

    public void permissionSuccess(int requestCode) {
        switch (requestCode) {
            case READ_PHONE_STATE_PERMISSION_REQUEST_CODE:
                break;
            case LOCATION_PERMISSION_REQUEST_CODE:
                break;
            default:
                break;
        }
    }

    public void permissionFailed(int requestCode) {

    }

    @Override
    public void onClick(View v) {
    }
}
